package api

import (
	"chat/api/handler"
	"chat/api/moddleware"
	"chat/consts"
	"github.com/gin-gonic/gin"
	"github.com/share309/gojwt"
)

func LoadRoutes(r *gin.Engine) {
	r.Use(moddleware.Cors())
	api := r.Group("/api")
	{
		user := api.Group("/user")
		{
			user.POST("/register", handler.Register)
			user.POST("/login", handler.Login)
			user.GET("/page", handler.Page)
			user.POST("/upload", handler.Upload)
			user.GET("/list", handler.List)
		}
		chat := api.Group("/chat")
		{
			chat.Use(gojwt.JWTAuth(consts.JWT_KEY))
			chat.GET("/ws", handler.Chat)
			chat.GET("/getHistory", handler.GetHistory)
		}
		admin := api.Group("/admin")
		{
			admin.POST("sendMessage", handler.SendMessage)
		}
	}
}
